﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;



namespace EAppointmentsWPF
{
	public partial class TimelineDay
	{
        int[,] arr=new int[24,20];
        public TimelineDay()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}

        private void TimelineDay_Loaded(object sender, RoutedEventArgs e)
        {
            ScrollViewer.ScrollToVerticalOffset(212);
        }
        void add(int index,string statusValue)
        {
            ContentControl cn = new ContentControl();
            cn.Width = 27;
            cn.Height = 27;
            cn.Style = this.Resources["BookedGlyphStyle"] as Style;
            cn.SetValue(Canvas.LeftProperty, (double)arr[index, 0]);
            arr[index, 0] += 27;
            cn.SetValue(Canvas.TopProperty, (double)arr[index, 1]);
            switch (statusValue)
            {
                case "Approved":
                    cn.Style = this.Resources["ApprovedGlyphStyle"] as Style;
                    break;

                case "Pending":
                    cn.Style = this.Resources["PendingGlyphStyle"] as Style;
                    break;

                case "Booked":
                    cn.Style = this.Resources["BookedGlyphStyle"] as Style;
                    break;
                case "Rejected":
                    cn.Style = this.Resources["RejectedGlyphStyle"] as Style;
                    break;
                case "Canceled":
                    cn.Style = this.Resources["CanceledGlyphStyle"] as Style;
                    break;
            }
            Canvas1.Children.Add(cn);
        }
        int IndexSearch(string time)
        {
            string[] str = new string[2];
            str = time.Split(':');
            int index = int.Parse(str[0]);
            if (time.Contains("p"))
            {
                if (index != 12)
                    index += 12;
            }
            else
            {
                if (index == 12)
                    index = 0;
            }
            return index;
        }
        public static DateTime StringToDateTime(string strDate)
        {
            string[] str = new string[3];
            str = strDate.Split('/');
            DateTime date = new DateTime(Int32.Parse(str[2]), Int32.Parse(str[0]), Int32.Parse(str[1]));
            return date;
        }
        private void txtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (txtBox.Text != "TextBox")
            {
                Canvas1.Children.Clear();
                arr[0, 0] = 5;
                arr[0, 1] = 0;
                for (int i = 1; i < 24; i++)
                {
                    arr[i, 0] = 5; //Starting Width
                    arr[i, 1] = arr[i - 1, 1] + 27; //Height
                }
                DateTime dateTime = StringToDateTime(txtBox.Text.Substring(0, 10));
                
                add(IndexSearch("6:30 pm"), "Pending");
                add(IndexSearch("4:57 pm"), "Booked");
                //add(IndexSearch("8:10 am"), "Approved");
                add(IndexSearch("4:30 pm"), "Rejected");
                //add(IndexSearch("11:30 pm"), "Canceled");

            }
        }
    }
}